<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>"延川县“三规合一”资源目录"</title>
<link href='./css/bootstrap.min.css' rel='stylesheet' />
<jsp:include page="/commonPages/admin-meta.jsp" flush="true" />
<!-- CSS files -->
<jsp:include page="/commonPages/admin-style.jsp" flush="true" />

<style type="text/css">
body {
	margin: 0;
	overflow: hidden;
	background: #fff;
}

#map {
	position: absolute;
	
	width: 100%;
	height: 90%;
	border: 1px solid #3473b7;
}
#select_map{
	 position: absolute;
	top: 5px;
	right:0px;
	height: 33px;
    float:right
	
}
#tool {
	position: relative;
	height: 33px;
	padding-top: 5;
}

.win_bg {
	background: #CCC;
	opacity: 0.2;
	filter: alpha(opacity = 20);
	position: absolute;
	left: 0px;
	top: 0px;
	width: 100%;
	height: 100%;
	z-index: 998;
}

.winTitle {
	background: #4192c9;
	height: 20px;
	line-height: 20px;
	position:relative;
}

.winTitle .title_left {
	font-weight: bold;
	color: #FFF;
	padding-left: 5px;
	float: left
}

.winTitle .title_right {
	float: right;
	padding-right: 3px;
}

.winTitle .title_right a {
	color: #FFF;
	text-decoration: none;
	padding-right: 3px;
}

.winTitle .title_right a:hover {
	text-decoration: underline;
	color: #FF0000;
	padding-right: 3px;
}

.transferPreference {
	border: 1px solid #D6E3F1;
	height: 20px;
	margin: 1px 30%;
	padding: 0 12px;
}

.winContent {
	padding: 5px;
	overflow-y: auto;
	height: 550px;
}

.popupWindow {
	right: 29px;
	top: 83px;
	position: absolute;
	width: 1100px;
	height: 600px;
	border: 2px solid #D6E3F1;
	background: #FFF;
	z-index: 9999;
}
.popupWindow1 {
	
	position: absolute;
	float: left;
	bottom:0px;

	border: 2px solid #D6E3F1;
	background: #FFF;
	z-index: 9999;
}
.button1{
	background-color:#4192c9;
	border:none;
	color:white;
	pading:15px 32px;
	text-align:center;
	text-decoration:none;
	display:inline-block;
	font-size:16px;
	margin:4px 2px;
	cursor:pointer;
	
	
}
</style>
<script src='js/printMap.js'></script>
<script src='js/MapToImg.js'></script>
<script src='./libs/SuperMap.Include.js'></script>
<script src='./js/jquery.js'></script>
<script type="text/javascript">
	var map = null;
	var layer = null;
	var url = null;
	var tempLayerID = null;
	var map, layer, mapurl;
	var MapPath = new Array();
	var url12 = "http://222.25.188.1:50118/iserver/services/map-SJK/rest/maps/林地规划图";
	
	function init() {
		
		GetMapService();
		
		
	}
	
	function GetMapService(){
		
		var url1 = "http://222.25.188.1:50118/iserver/services/map-SJK/rest/maps"
		var MyMapService = new SuperMap.REST.MapService(url1);
		MyMapService.events.on({
			"processCompleted": MapServiceCompleted,
			"processFailed":MapServiceFailed,
		});
		MyMapService.processAsync();
	}
	var SubMap = new Array();
	var SubUrl = new Array();
	function MapServiceCompleted(MapServiceEventArgs) {
		 var result =MapServiceEventArgs.originResult; 
		 
		 if (result) {
			
						//alert(getMapServiceEventArgs.result.name);
						for (var j = 0; j < result.length; j++){ 
							SubMap.push(result[j].name);
							SubUrl.push(result[j].path);
						}
					
				}
		 	
			//alert(SubMap[0]);
			installMap(SubMap,SubUrl);
			
			}
	function show1(){
		$("#popupWin").css("display", "block");
		
	}
	function installMap(SubMap,SubUrl) {

		map = new SuperMap.Map("map",{controls: [
		                                         new SuperMap.Control.Navigation({
		                                          dragPanOptions: {
		                                          enableKinetic: true
		                                            },
		                                            zoomBoxEnabled:false
		                                            
		                                         })]
		                    });
		                    		//初始化复杂缩放控件类
		                    		panzoombar=new SuperMap.Control.PanZoomBar();
		                    		// 是否固定缩放级别为[0,16]之间的整数，默认为false
		                    		panzoombar.forceFixedZoomLevel=true;
		                    		//是否显示滑动条，默认值为false
		                    		panzoombar.showSlider=true;
		                    		/*点击箭头移动地图时，所移动的距离占总距离（上下移动的总距离为高度，左右移动的总距离为宽度）
		                    		的百分比，默认为null。 例如：如果slideRatio 设为0.5, 则垂直上移地图半个地图高度.*/
		                    		panzoombar.slideRatio=0.5; 
		                    		//设置缩放条滑块的高度，默认为120
		                    		panzoombar.sliderBarHeight=180;
		                    		//设置缩放条滑块的宽度，默认为13
		                    		panzoombar.sliderBarWidth=17;
		                    		map.addControl(panzoombar);
		                    		
		//alert(SubUrl[0]);
		layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url12, {transparent: true, cacheEnabled: true}, {maxResolution:"auto"});
		layer.events.on({"layerInitialized":addLayer});
		var layersList = "";
		
		
	}
	
	function ShowMap(mapurl){
		 if(mapurl){
				mapurl = decodeURI(mapurl);
				//alert(mapurl);
				var getLayersInfoService = new SuperMap.REST.GetLayersInfoService(mapurl);
	            getLayersInfoService.events.on({ "processCompleted": getLayersInfoCompleted});
	            getLayersInfoService.processAsync();
				 if(layer!=null){
				 map.removeLayer(layer);
				 layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", mapurl, {transparent: true, cacheEnabled: false, redirect: true, layersID: tempLayerID}, {maxResolution: "auto", bufferImgCount: 0});
				 layer.events.on({"layerInitialized":addLayer});
				 layer.redraw();
				 }
			 } 
		 
	}
	 var subLayers = new Array();
     function getLayersInfoCompleted(getLayersInfoEventArgs) {
    	 subLayers = [];
         if (getLayersInfoEventArgs.result) {
             {
                 if (getLayersInfoEventArgs.result.subLayers) {
                     for (var j = 0; j < getLayersInfoEventArgs.result.subLayers.layers.length; j++) {
                         subLayers.push(getLayersInfoEventArgs.result.subLayers.layers[j]);
                     }
                 }
             }
         }
         installPanel(subLayers);
     }

     //组装操作面板，显示子图层列表，并初始化地图显示
     function installPanel(subLayers) {
         var layergroup = "";
         //alert(subLayers.length);
         for (var i = 0; i < subLayers.length; i++) {
        	 
             if (eval(subLayers[i].visible) == true) {
            	 layergroup += '<label class = "check" style="line-height: 28px; display: block"><input type="checkbox"   id="layersList' + i + '" name="layersList" value="' + subLayers[i].name + '" checked=true title="是否可见" />' + subLayers[i].name + '</label>';
             }
             else {
            	 layergroup += '<label class="checkbox" style="line-height: 28px; display: block"><input type="checkbox" class = "checkboxSel" id="layersList' + i + '" name="layersList" value="' + subLayers[i].name + '" title="是否可见"  />' + subLayers[i].name + '</label>';
             }
         }
         
         show(layergroup);
         $(".check").click(setLayerStatus);

         //样式为BootStrap框架设置
         $(".check").hover(function () {
             $(this).addClass("label-success");
         }, function () {
             $(this).removeClass("label-success");
         });
         createTempLayer();
     }

     //创建临时图层来初始化当前地图显示
     function createTempLayer() {
         //子图层控制参数必设：url、mapName、SetLayerStatusParameters
         var layerStatusParameters = new SuperMap.REST.SetLayerStatusParameters();
         layerStatusParameters = getLayerStatusList(layerStatusParameters);

         var setLayerStatusService = new SuperMap.REST.SetLayerStatusService(url);
         setLayerStatusService.events.on({ "processCompleted": createTempLayerCompleted});
         setLayerStatusService.processAsync(layerStatusParameters);
     }

     //获取当前地图子图层状态信息
     function getLayerStatusList(parameters) {
         var layersList = document.getElementsByName("layersList");
         for (var i = 0; i < layersList.length; i++) {
             var layerStatus = new SuperMap.REST.LayerStatus();
             layerStatus.layerName = layersList[i].value;
             layerStatus.isVisible = eval(layersList[i].checked);
             parameters.layerStatusList.push(layerStatus);
         }
         //设置资源在服务端保存的时间，单位为分钟，默认为10
         parameters.holdTime = 30;
         return parameters;
     }

     //与服务器交互成功，创建临时图层
     function createTempLayerCompleted(createTempLayerEventArgs) {
         tempLayerID = createTempLayerEventArgs.result.newResourceID;

     }

    function showLayer(){
    	$("#popupWin1").css("display", "block");
    	
    }
     //子图层可见性控制
     function setLayerStatus() {
        
         //方法二：通过TiledDynamicRESTLayer的属性layersID来控制子图层的可见性，推荐使用此方法
         var layersList = document.getElementsByName("layersList");
         var str = "[0:";
         for (var i = 0; i < layersList.length; i++){
             if(eval(layersList[i].checked) == true)
             {
                 if(i<layersList.length)
                 {
                     str += i.toString();
                 }
                 if(i<layersList.length-1)
                 {
                     str += ",";
                 }
             }
         }
         str += "]";
         //当所有图层都不可见时
         if(str.length<5)
         {
             str = "[]";
         }
         layer.params.layersID = str;
         layer.redraw();

     }

     //与服务器交互成功，修改临时图层的子图层可见性
     function setLayerStatusCompleted(setLayerStatusEventArgs) {
         //刷新显示临时图层
         layer.redraw();
     }
	
	function addLayer() {
		map.addLayers([layer]);
        map.setCenter(new SuperMap.LonLat(37424952.75 , 4085429.08 ), 0);
    }
	function MapServiceFailed(){}
	
	function showWindow(winMessage) {
		
			
	}
	window.close = function() {
		$("#popupWin").css("display", "none");
		
	}
	window.startMove = function(o, e) {
		var wb;
		if (SuperMap.Browser.name === "msie" && e.button === 1)
			wb = true;
		else if (e.button === 0)
			wb = true;
		if (wb) {
			var x_pos = parseInt(e.clientX - o.parentNode.offsetLeft);
			var y_pos = parseInt(e.clientY - o.parentNode.offsetTop);
			if (y_pos <= o.offsetHeight) {
				document.documentElement.onmousemove = function(mEvent) {
					var eEvent = (SuperMap.Browser.name === "msie") ? event
							: mEvent;
					o.parentNode.style.left = eEvent.clientX - x_pos + "px";
					o.parentNode.style.top = eEvent.clientY - y_pos + "px";
				}
			}
		}
	}
	window.stopMove = function(o, e) {
		document.documentElement.onmousemove = null;
	}
	
	function show(winMessage) {
		if (document.getElementById("popupWin1")) {
				$("#popupWin1").css("display", "block");
				
			} else {
				$("<div id='popupWin1'></div>").addClass("popupWindow1").appendTo(
						$("#result"));	
			}
		
		$("#popupWin1").css("display", "none");
	var str = "";
	str += '<div class="winTitle" onMouseDown="startMove(this,event)" onMouseUp="stopMove(this,event)"><span class="title_left">图层管理器 </span><span class="title_right"><a href="javascript:closeWindow()" title="关闭窗口">关闭</a></span><br style="clear:left"/></div>'; //标题栏

	str += '<div class="winContent" style="overflow-y:auto;height:400px;">';
	str += winMessage;
	str += '</div>';
	$("#popupWin1").html(str);
	document.getElementById("popupWin1").style.width = "250px";
	document.getElementById("popupWin1").style.height = "300px";
}
window.closeWindow = function() {
	
	$("#popupWin1").css("display", "none");
	
}
//地图打印和截图
function createPrintMap1(id){
	createPrintMap(id);
}

function mapToImg1(){
	MapToImg&&MapToImg.excute(map);
	}
function printMap1(){
	printMap&&printMap.excute(map);
}
function enlarge(){
	
	
	zoombox = new SuperMap.Control.ZoomBox({"autoActivate":true})
	
	map.addControl(zoombox);//添加控件);
	
	
}
function Shrink(){
	
	zoombox1=new SuperMap.Control.ZoomBox({"autoActivate":true});
		//是否将该控件设置为拉框缩小，默认为false，拉框放大
		zoombox1.out=true;
		map.addControl(zoombox1);//添加控件);
	
}
function ShowMap1(map1){
	var name = map1.options[map1.options.selectedIndex].text;
	document.all.sel.options[map1.options.selectedIndex].selected=true;
	//alert(name);
	var mapurl = "http://222.25.188.1:50118/iserver/services/map-SJK/rest/maps/"+name;
   
	
	 if(mapurl){
			mapurl = decodeURI(mapurl);
			var getLayersInfoService = new SuperMap.REST.GetLayersInfoService(mapurl);
            getLayersInfoService.events.on({ "processCompleted": getLayersInfoCompleted});
            getLayersInfoService.processAsync();
			 if(layer!=null){
			 map.removeLayer(layer);
			 layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", mapurl, {transparent: true, cacheEnabled: false, redirect: true, layersID: tempLayerID}, {maxResolution: "auto", bufferImgCount: 0});
			 layer.events.on({"layerInitialized":addLayer});
			 layer.redraw();
			 }
		 } 
	 
	}
	
</script>
</head>
<body onload="init()">
	<div id="wrapper">

		<!-- Navigation -->
		<jsp:include page="/commonPages/admin-navigator.jsp" flush="true" />
		<div id="page-wrapper">
		<div id='result' class='container'></div>
	<div id = "tool">
	<button onclick ="mapToImg1()" class= "button1" title = "导出" style = " width :20px;height:20px;border:0;background:url('./img/Out.png') no-repeat left top"></button>
	<button onclick = "printMap1()"class= "button1" title = "打印" style = " width :20px;height:20px;border:0;background:url('./img/P.png') no-repeat left top"></button>
	<input  type =button onclick = "showLayer()" title = "图层管理器" style = " width :20px;height:20px;border:0;background:url('./img/Layer.png') no-repeat left top">
	<input  type =button onclick = "enlarge()" title = "放大" style = " width :20px;height:20px;border:0;background:url('./img/fangda.png') no-repeat left top">
	<input  type =button onclick = "Shrink()" title = "缩小" style = " width :20px;height:20px;border:0;background:url('./img/suoxiao.png') no-repeat left top">
	<div id = "select_map">
	资源目录：
	
	<select id = "sel" onchange = "ShowMap1(this)">
	<option value = "map1">林地规划图 </option>
	
	</select>
	</div>
	</div>
	<div id="map" >
	</div>
	</div>
		<jsp:include page="/commonPages/admin-script.jsp" flush="true" />

	</div>
	
</body>
</html>